{% load bootstrap_admin_template_tags %}
<div class="form-row form-group{% if line.errors and field.field.errors %} has-error{% endif %}{% if not line.has_visible_field %} hidden{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}{% if not line.fields|length_is:'1' %} field-box {{ css_field_box }}{% endif %}">
    {% if field.is_checkbox %}
      <div class="checkbox">
        {% if not is_tabular %}
          <label>
            {{ field.field }} {{ field.field.label }}
          </label>
        {% else %}
          {{ field.field }}
        {% endif %}

        {% for error in field.field.errors %}
          <p class="help-block error">{{ error }}</p>
        {% endfor %}

        {% if field.field.help_text %}
          <p class="help-block">
            {{ field.field.help_text|safe }}
          </p>
        {% endif %}
      </div>
    {% else %}
      {% with field.field|widget_type as widget_type %}
        <div class="widget_type__{{ widget_type }}">
          {% if widget_type == 'adminsplitdatetime' %}
            {% if not is_tabular %}
              {{ field.label_tag }}
            {% endif %}
            {% if field.is_readonly %}
              <p>{{ field.contents|linebreaksbr }}</p>
            {% else %}
              {{ field.field }}
            {% endif %}

            {% for error in field.field.errors %}
              <p class="help-block error">{{ error }}</p>
            {% endfor %}

            {% if field.field.help_text %}
              <p class="help-block">
                {{ field.field.help_text|safe }}
              </p>
            {% endif %}
          {% else %}
            {# only show the label for visible fields #}
            {% if not field.field.is_hidden %}
              {% if not is_tabular %}
                {{ field.label_tag }}
              {% endif %}
            {% endif %}
              {% if field.is_readonly %}
                <p>{{ field.contents|linebreaksbr }}</p>
              {% else %}
                {% if widget_type == 'adminradioselect' or widget_type == 'checkboxselectmultiple' or widget_type == 'readonlypasswordhashwidget' or widget_type == 'adminfilewidget' %}
                  {{ field.field }}
                {% else %}
                  {{ field.field|add_class:"form-control" }}
                {% endif %}
              {% endif %}

              {% for error in field.field.errors %}
                <p class="help-block error">{{ error }}</p>
              {% endfor %}

              {% if field.field.help_text %}
                <p class="help-block">
                  {{ field.field.help_text|safe }}
                </p>
              {% endif %}
          {% endif %}
        </div>
      {% endwith %}
    {% endif %}
</div>

